package com.jswj.media.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.jswj.media.domain.Media;
import com.jswj.media.service.IMediaService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 媒体平台Controller
 *
 * @author whh
 * @date 2021-06-26
 */
@Controller
@RequestMapping("/screenshot/media")
public class MediaController extends BaseController {
    private String prefix = "screenshot/media";

    @Autowired
    private IMediaService mediaService;

    @RequiresPermissions("screenshot:media:view")
    @GetMapping()
    public String media() {
        return prefix + "/media";
    }

    /**
     * 查询媒体平台列表
     */
    @RequiresPermissions("screenshot:media:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Media media) {
        startPage();
        List<Media> list = mediaService.selectMediaList(media);
        return getDataTable(list);
    }

    /**
     * 导出媒体平台列表
     */
    @RequiresPermissions("screenshot:media:export")
    @Log(title = "媒体平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Media media) {
        List<Media> list = mediaService.selectMediaList(media);
        ExcelUtil<Media> util = new ExcelUtil<Media>(Media.class);
        return util.exportExcel(list, "媒体平台数据");
    }

    /**
     * 新增媒体平台
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存媒体平台
     */
    @RequiresPermissions("screenshot:media:add")
    @Log(title = "媒体平台", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Media media) {
        return toAjax(mediaService.insertMedia(media));
    }

    /**
     * 修改媒体平台
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Media media = mediaService.selectMediaById(id);
        mmap.put("media", media);
        return prefix + "/edit";
    }

    /**
     * 修改保存媒体平台
     */
    @RequiresPermissions("screenshot:media:edit")
    @Log(title = "媒体平台", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Media media) {
        return toAjax(mediaService.updateMedia(media));
    }

    /**
     * 删除媒体平台
     */
    @RequiresPermissions("screenshot:media:remove")
    @Log(title = "媒体平台", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(mediaService.deleteMediaByIds(ids));
    }
}
